package com.calms.study.app.controller;

import cn.hutool.core.lang.Pair;
import com.calms.study.infra.dto.DbOneDTO;
import com.calms.study.infra.dto.TempTableDTO;
import com.calms.study.infra.service.DbOneService;
import com.calms.study.infra.service.TempTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 临时表
 *
 * @author code@code.com
 * @date 2024-11-19 12:09:39
 */
@Slf4j
@RestController
@RequestMapping("/temp/table")
public class TempTableController {

    @Autowired
    private TempTableService tempTableService;
    @Autowired
    private DbOneService dbOneService;

    @PostMapping("/saveTestData")
    public ResponseEntity<Pair<String, Object>> saveTestData(@RequestBody TempTableDTO tempTableDTO) {
        return ResponseEntity.ok(Pair.of("data", tempTableService.saveTestData(tempTableDTO)));
    }

    @PostMapping("/saveTestDataDbOne")
    public ResponseEntity<Pair<String, Object>> saveTestDataDbOne(@RequestBody DbOneDTO tempTableDTO) {
        return ResponseEntity.ok(Pair.of("data", dbOneService.saveTestData(tempTableDTO)));
    }

    @PostMapping("/pageParams")
    public ResponseEntity<Pair<String, Object>> pageParams(@RequestBody TempTableDTO tempTableDTO) {
        return ResponseEntity.ok(Pair.of("data", tempTableService.pageParams(tempTableDTO)));
    }

    @PostMapping("/pageDbOneParams")
    public ResponseEntity<Pair<String, Object>> pageDbOneParams(@RequestBody DbOneDTO dbOneDTO) {
        return ResponseEntity.ok(Pair.of("data", dbOneService.pageParams(dbOneDTO)));
    }

}
